//
//  PartyImageDetailViewController.m
//  homeland
//
//  Created by caesar on 14-8-2.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//

#import "PartyImageDetailViewController.h"

@interface PartyImageDetailViewController ()

@end

@implementation PartyImageDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSString *name = [self.config objectForKey:@"name"];
    self.title = name;
    name = [name stringByAppendingFormat:@".jpg"];
    UIImage* image = [UIImage imageNamed: name ];
    int screenWidth =0;
    if (iPhone5) {
        screenWidth = 640;
    }else{
        screenWidth = 320;
    }
 
    float scale = 320/image.size.width;
    image = [self scaleImage:image toScale:scale];
    NSLog(@"height = %f",image.size.height);
    UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,  image.size.height+20)];
    [imageView setImage:image];
    [self.scrollView addSubview:imageView];
    
    self.scrollView.contentSize = imageView.frame.size;
    [self.view addSubview: self.scrollView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize

{
    
    UIGraphicsBeginImageContext(CGSizeMake(image.size.width * scaleSize, image.size.height * scaleSize));
    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height * scaleSize)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return scaledImage;
                                
}

@end
